using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Collections;
using System.IO;
using Microsoft.Practices.RecipeFramework;
using EnvDTE;
using VSSDKAssist.Assets.Actions.Base;
using VSSDKAssist.Recipes.Common.Helpers;

namespace VSSDKAssist.Recipes.Common.Actions
{
	/// <summary>
	/// Action that finds an entry on a resx file
	/// </summary>
	public class FindResxEntryAction : ActionBase
	{
		private ProjectItem resxProjectItem;

		/// <summary>
		/// Gets or sets the RESX project item.
		/// </summary>
		/// <value>The RESX project item.</value>
		[Input(Required = true)]
		public ProjectItem ResxProjectItem
		{
			get { return resxProjectItem; }
			set { resxProjectItem = value; }
		}

		private string resourceId;

		/// <summary>
		/// Gets or sets the resource id.
		/// </summary>
		/// <value>The resource id.</value>
		[Input(Required = true)]
		public string ResourceId
		{
			get { return resourceId; }
			set { resourceId = value; }
		}

		private ResXDataNode node;

		/// <summary>
		/// Gets or sets the node.
		/// </summary>
		/// <value>The node.</value>
		[Output]
		public ResXDataNode Node
		{
			get { return node; }
			set { node = value; }
		}

		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			string resxFileName = this.ResxProjectItem.Properties.Item("FullPath").Value.ToString();

			this.node = ResxHelper.GetResxDataNodeById(
				this.Site as IServiceProvider,
				resxFileName,
				this.resourceId);
		}
	}
}